package cn.lovefix.user.service.impl;

import cn.lovefix.base.pageList;
import cn.lovefix.user.domain.User;
import cn.lovefix.user.mapper.UserMapper;
import cn.lovefix.user.query.queryByname;
import cn.lovefix.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public User pick(User user) {
        User user1 = userMapper.pick(user);

//        System.out.println(user1+"我看看你到底查询的出来不");
//        System.out.println(user1.getStat()+"我是权限");
        if (user1==null) {
            throw new RuntimeException("用户账户密码不存在");
        }else if (user1.getStat().toString()=="0") {
            throw new RuntimeException("用户被禁用");
        }
        return user1;
    }

    @Override
    public List<User> findAll() {

        return userMapper.findAll();
    }

    @Override
    public void del(Long id) {

        userMapper.del(id);

    }

    @Override
    public void update(User user) {
        userMapper.update(user);

    }

    @Override
    public void add(User user) {
        userMapper.add(user);

    }

    @Override
    public pageList<User> query(queryByname query) {
        Integer totals = userMapper.queryBycount(query);
        List<User> list = userMapper.query(query);
        pageList<User> pageList = new pageList<>(totals, list);
        return pageList;
    }
}
